def isPrime(a):
    if a == 1: return False
    test = True
    k = a - 1
    while k > 1:
        if not a % k:
            test = False
            break
        k -= 1
    return test

b = input()
e = []
for i in range(len(b)):
     for k in range(i + 1, len(b) + 1):
         a = int(b[i:k])
         if isPrime(a):
             e += [a]
print(max(e) if e else 0)